use thiserror::Error;

/// 自定义错误类型，用于标准化错误处理
#[allow(dead_code)]
#[derive(Error, Debug)]
pub enum ScannerError {
    #[error("IO错误: {0}")]
    IoError(#[from] std::io::Error),

    #[error("数据库错误: {0}")]
    DbError(#[from] rusqlite::Error),

    #[error("解析错误: {0}")]
    ParseError(String),

    #[error("文件不存在: {0}")]
    FileNotFound(String),

    #[error("计算MD5错误: {0}")]
    Md5Error(String),

    #[error("参数错误: {0}")]
    ArgError(String),

    #[error("其他错误: {0}")]
    Other(String),
}

impl From<String> for ScannerError {
    fn from(msg: String) -> Self {
        ScannerError::Other(msg)
    }
}

impl From<&str> for ScannerError {
    fn from(msg: &str) -> Self {
        ScannerError::Other(msg.to_string())
    }
}
